/*
 *	               _ooOoo_ 
 *	              o8888888o 
 *	              88" . "88 
 *	              (| -_- |) 
 *	              O\  =  /O 
 *	           ____/`---'\____ 
 *	         .'  \\|     |//  `. 
 *	        /  \\|||  :  |||//  \ 
 *	       /  _||||| -:- |||||-  \ 
 *	       |   | \\\  -  /// |   | 
 * 	       | \_|  ''\---/''  |   | 
 * 	       \  .-\__  `-`  ___/-. / 
 * 	    ___ `. .'  /--.--\  `. . __ 
 *	  ."" '<  `.___\_<|>_/___.'  >'"". 
 *	 | | :  `- \`.;`\ _ /`;.`/ - ` : | | 
 *	 \  \ `-.   \_ __\ /__ _/   .-` /  / 
 *======`-.____`-.___\_____/___.-`____.-'====== 
 *                   `=---=' 
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
 *佛祖保佑       永无BUG 
 * File name:         CMyEncrypt.java
 * Copyright@blog.ilvelh.com(China)
 * Editor:           JDK1.7_40
 */
package com.ilvelh.tools;

import java.util.UUID;

/**
 * 获取随机字符
 * <p>
 * Author: ilvelh
 * <p>
 * Date:2013-8-15 Time:下午2:23:27
 * <p>
 */
public class CMyEncrypt {
	private static final String[] l = { "0", "1", "2", "3", "4", "5", "6", "7",
			"8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
			"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x",
			"y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
			"L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
			"Y", "Z" };

	private static int count = 100;

	private static int getCount() {
		if (count > 999)
			count = 100;
		return count++;
	}

	// TentoN(这里是你想转换的数 ,这里是你想转换为多少进制 2-62之间）
	public static String TentoN(long value, int number) {
		if (number <= 1 || number > l.length) {
			throw new RuntimeException("Faild");
		}
		// 负数处理
		if (value < 0) {
			return "-" + TentoN(0 - value, number);
		}
		if (value < number) {
			return l[(int) value];
		} else {
			long n = value % (long) number;
			return (TentoN(value / number, number) + l[(int) n]);
		}
	}

	/**
	 * 获取随机字符串，使用62进制,后面追加UUID
	 * 
	 * @return String
	 */
	public static String rshort62AndUUID() {
		String s = TentoN((System.currentTimeMillis() - 1323333000000L), 62)
				+ TentoN((long) getCount(), 62);
		s += UUID.randomUUID().toString().substring(0, 8);
		return s;

	}

	/**
	 * 获取随机字符串，使用62进制
	 * 
	 * @return String
	 */
	public static String rshort62() {
		String s = TentoN((System.currentTimeMillis() - 1323333000000L), 62)
				+ TentoN((long) getCount(), 62);
		return s;

	}

}
